﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YJKCopyModel.AxisTransModel;
using System.Windows.Forms;


namespace YJKCopyModel.Command
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
    public class CmdReadCADDoors : IExternalCommand
	{
        public Result Execute(ExternalCommandData commandData, ref string msg, ElementSet elems)
		{
            commandData.Application.Application.FailuresProcessing += this.OnFailuresProcessing;


            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection sel = uidoc.Selection;

            OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "DWG Files (*.dwg)|*.dwg";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string fileName = openFileDialog.FileName;


                    string resolvepath = @"D:\Program Files\Hongye\HYMEI2018\bin";

                    AppDomain currentdomain = AppDomain.CurrentDomain;

                    var assemblies = currentdomain.GetAssemblies();

                    YJKCopyModel.Basic.Utils.GetCADTextInfl1(fileName);


                    return Autodesk.Revit.UI.Result.Succeeded;
                }
                catch (Exception ex)
                {
                    string sss = ex.Message;
                    MessageBox.Show(sss);
                    return Autodesk.Revit.UI.Result.Failed;
                }

                return Autodesk.Revit.UI.Result.Failed;
            }

            commandData.Application.Application.FailuresProcessing -= this.OnFailuresProcessing;
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private void OnFailuresProcessing(object sender, FailuresProcessingEventArgs e)
		{
			FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
			string transactionName = failuresAccessor.GetTransactionName();
			IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();
			bool flag = failureMessages.Count == 0;
			if (flag)
			{
				bool flag2 = e.GetProcessingResult() > 0;
				if (!flag2)
				{
					e.SetProcessingResult((FailureProcessingResult)0);
				}
			}
			else
			{
				foreach (FailureMessageAccessor failureMessageAccessor in failureMessages)
				{
					bool flag3 = (int)failureMessageAccessor.GetSeverity() == 2;
					if (flag3)
					{
						failuresAccessor.ResolveFailure(failureMessageAccessor);
					}
					else
					{
						bool flag4 = (int)failureMessageAccessor.GetSeverity() == 1;
						if (flag4)
						{
							failuresAccessor.DeleteWarning(failureMessageAccessor);
						}
					}
				}
				e.SetProcessingResult((FailureProcessingResult)1);
			}
		}
	}
}
